﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Zatify.Domain.Abstract;
using System.Web.Routing;
using Zatify.Domain.Concrete;
using Zatify.WebUI.Infrastructure.Concrete;

namespace Zatify.WebUI.Infrastructure.Filters
{
    public class ZatifyAdminAuthorizeAttribute : AuthorizeAttribute
    {
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            if (!filterContext.HttpContext.Request.IsAuthenticated ||
                ((filterContext.HttpContext.User as ZatifyPrincipal).UserRole != UserRole.SystemAdmin
              || (filterContext.HttpContext.User as ZatifyPrincipal).UserRole != UserRole.SystemAdmin))
            {
                //filterContext.HttpContext.Response.Redirect("~/Admin/Account/Login?ReturnUrl=" + filterContext.HttpContext.Request.Url.PathAndQuery);
                filterContext.Result = new RedirectResult("/Admin/Account/Login?ReturnUrl=" + filterContext.HttpContext.Request.Url.PathAndQuery);
            }

            base.OnAuthorization(filterContext);
        }
    }
}